package com.princess.demok.mvvm.repository

import androidx.lifecycle.MutableLiveData
import com.princess.baselib.utils.LogUtils
import com.princess.baselib.utils.SharedPreferencesUtils
import com.princess.demok.base.repository.ApiRepository
import com.princess.demok.common.State
import com.princess.demok.net.data.HistoryData
import com.princess.demok.network.dataConvert
import com.princess.demok.utils.Constant
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.util.*

/**
 * @author: xha
 * @date: 2021/6/2 17:17
 * @Description:
 */
class HistoryListRepository(var loadState: MutableLiveData<State>) : ApiRepository() {

    suspend fun getData(): List<HistoryData> {
        val calendar = Calendar.getInstance()
        return apiService.historyDay(
            Constant.JUHE_KEY,
            "1.0", calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH)
        ).dataConvert(loadState)
    }

    suspend fun getData1(): List<HistoryData> {
        val calendar = Calendar.getInstance()
        LogUtils.i("开启请求1")
        var list: List<HistoryData> = arrayListOf()
        val data = apiService.historyDay(
            Constant.JUHE_KEY,
            "1.0", calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH)
        )
        LogUtils.i("data ${data.errorCode}  ${data.result}")
        list = data.result
        return list
    }

}